﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _2021_6_4
{
    public enum janKenPunch
    {
        剪刀 = 1,
        石头,
        布
    }
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                #region 开屏介绍及初始化
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("——————欢迎进入游戏世界——————");
                Console.WriteLine("****************************************");
                Console.WriteLine("**************猜拳，开始****************");
                Console.WriteLine("****************************************");
                Console.WriteLine("--出拳规则：1、剪刀 2、石头 3、布");
                int key;
                NPC enemy;
                Player player;
                Judgment jud;
                #endregion

                #region 选择对手
                while (true)
                {
                    Console.WriteLine("请选择你的对手：（1：刘备 2:孙权 3：曹操）");
                    key = int.Parse(Console.ReadLine()); ;
                    if (key >= 1 && key <= 3)
                    {
                        enemy = RetrunNpc(key);
                        break;
                    }
                    else
                    {
                        Console.WriteLine("输入有误！");
                    }
                }
                #endregion

                #region 创建玩家和裁判的对象
                Console.WriteLine("请输入你的名字：");
                player = new Player(Console.ReadLine());
                Console.WriteLine();
                jud = new Judgment(Player: player.PlayerName, Npc: enemy.NpcName);
                #endregion

                #region 游戏过程
                    while (true)
                    {
                         Console.WriteLine("请出拳：");
                         key = int.Parse(Console.ReadLine());
                         if (key >= 1 & key <= 3)
                         {
                            jud.Decide(player: player.DoJanKenPunch(key), npc: enemy.DoJanKenPunch());
                            Console.WriteLine("信息:\n" + player +"\n" + enemy);
                            Console.WriteLine("按y开始下一局，任意键退出：");

                            if ((Console.ReadLine().Equals("y")) == false)
                            {
                                break;
                            }
                         }
                        else
                        {
                            Console.WriteLine("输入有误！");
                            continue;
                        }

                    }
                #endregion

                #region 游戏结束
                Console.WriteLine("\n\r-----------------------------------");
                Console.WriteLine(jud);
                Console.WriteLine("按y开始下一局，任意键退出");
                if ((Console.ReadLine().Equals("y")) == false)
                {
                    break;
                }
                #endregion
            }

    
        }
        /// <summary>
        ///  返回一个对手对象       
        /// </summary>
        /// <param name="key"></param>
        /// <returns>NPC</returns>
        public static NPC RetrunNpc(int key)
        {
            switch (key)
            {
                case 1:
                    return  new NPC("刘备");
                case 2:
                    return  new NPC("孙权");
                default:
                    return  new NPC("曹操");
            }


        }


    }
}
